Skip to content

Conversation

@Sube-py
Copy link
Contributor

@Sube-py Sube-py commented Dec 2, 2025

When using environment variables to override multi-level configurations, an error will occur if the configuration is of a complex type.

pydantic version: 2.11.9
pydantic-core version: 2.33.2
pydantic-core build: profile=release pgo=false
python version: 3.12.7 (main, Oct 16 2024, 07:12:08) [Clang 18.1.8 ]
platform: macOS-26.1-arm64-arm-64bit
related packages: pydantic-settings-2.8.1 typing_extensions-4.15.0
commit: unknown

Reproduce code:

from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings, SettingsConfigDict


class EmbeddingModel(BaseModel):
    model: str = 'text-embedding-3-small'
    keys: list[str] = Field(default_factory=list)


class LLM(BaseModel):
    embeddings: dict[str, EmbeddingModel] = Field(default_factory=dict)


class LLMSettings(BaseSettings):
    llm: LLM = Field(default_factory=lambda: LLM())

    model_config = SettingsConfigDict(env_prefix='my_prefix_', env_nested_delimiter='__')


# export my_prefix_llm__embeddings__openai__keys='["sk-..."]'
# export my_prefix_llm__embeddings__qwen__keys='["sk-..."]'
print(LLMSettings().model_dump()) # raise error

@hramezani
Copy link
Member

Thanks @Sube-py for the PR.
Please add the example in the PR description as a test

@Sube-py
Copy link
Contributor Author

Sube-py commented Dec 2, 2025

@hramezani plz check.

@hramezani
Copy link
Member

@hramezani plz check.

Thanks @Sube-py please check the comments

@Sube-py
Copy link
Contributor Author

Sube-py commented Dec 3, 2025

@hramezani Review it please.

if files is None:
return {}
if isinstance(files, (str, os.PathLike)):
if not isinstance(files, Sequence) or isinstance(files, (str, bytes)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so sorry, please revert this part. I was about to mention the PR creator on the other PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XD, has been reverted.

@hramezani
Copy link
Member

Thanks @Sube-py

@hramezani hramezani merged commit c158510 into pydantic:main Dec 3, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants